home *** CD-ROM | disk | FTP | other *** search
-
- #define NOCOMM
- #include <windows.h>
-
- #include "hugearr.h"
-
- /* Get the handle of the next unused array slot. */
- static int CDECL
- VBHugeGetFreeArray(PHUGEDESC pArray)
- {
- int i = 0;
-
- /* loop until found or out of entries */
- while (i < NumArrays && pArray -> handle != NULL)
- {
- ++pArray;
- ++i;
- }
-
- if (i == NumArrays)
- /* didn't find a spot */
- return HA_TOOMANYARRAYS;
-
- /* found one, return index to it */
- return i;
- }
-
- /* Allocate or reallocate the Global memory space required for a huge array,
- and setup the array description structure. */
- static int CDECL
- VBHugeAlloc(PHUGEDESC pArray, int recsize, long ubound, BOOL realloc)
- {
- int perseg; /* #elements per segment */
- long newsiz; /* actual size of array */
- HANDLE handle; /* temp handle for alloc */
-
- /* #elements per segment. */
- perseg = (int) (0x10000L / (long) recsize);
- /* size of array in bytes is offset of beginning of last element plus length of an element. */
- newsiz = HugeElementOffset(ubound, perseg, recsize) + (long) recsize;
-
- if (!realloc)
- /* allocate a new array */
- handle = GlobalAlloc(GMEM_MOVEABLE || GMEM_ZEROINIT, newsiz);
- else
- /* attempt to reallocate the existing array */
- handle = SjsGlobalReAlloc(pArray -> handle, newsiz, GMEM_MOVEABLE || GMEM_ZEROINIT);
-
- if (handle == NULL)
- /* out of memory */
- return HA_OUTOFMEMORY;
-
- /* save new handle */
- pArray -> handle = handle;
- /* save element size */
- pArray -> recsize = recsize;
- /* note - number of elements is ubound + 1. */
- pArray -> ubound = ubound;
- pArray -> perseg = perseg;
-
- return HA_OK;
- }
-
- /* Dimension a huge array and return a handle to it. */
- /* VBM: Declare Function VBHugeDim% Lib "hugearr.dll" Alias "VBHugeDim" (ByVal recsize%, ByVal limit&) */
- int FAR PASCAL
- VBHugeDim(int recsize, long ubound)
- {
- int hArray; /* handle to array to dimension */
- PHUGEDESC pArray; /* pointer to array descriptor */
- int ret; /* return value from HugeAlloc */
-
- pArray = (PHUGEDESC) LocalLock(hLocalMem);
-
- /* find a free array */
- if ((hArray = VBHugeGetFreeArray(pArray)) == HA_TOOMANYARRAYS)
- {
- /* couldn't find one, return error.*/
- LocalUnlock(hLocalMem);
- return HA_TOOMANYARRAYS;
- }
-
- /* allocate new array */
- ret = VBHugeAlloc(pArray + hArray, recsize, ubound, FALSE);
- LocalUnlock(hLocalMem);
-
- /* if an error occured during alloc */
- if (ret < 0)
- /* return the error, else */
- return ret;
- else
- /* return the handle to the array */
- /* VB users think handles start at 1 */
- return hArray + 1;
- }
-
- /* Redimension a huge array and return a handle to it. */
- /* VBM: Declare Function VBHugeRedim% Lib "hugearr.dll" Alias "VBHugeRedim" (ByVal hArray%, ByVal limit&) */
- int FAR PASCAL
- VBHugeRedim(int hArray, long ubound)
- {
- PHUGEDESC pArray; /* pointer to array desciptor */
- register ret; /* return code of HugeAlloc */
-
- DecCheckHandle(hArray);
-
- pArray = (PHUGEDESC) LocalLock(hLocalMem) + hArray;
-
- if (pArray -> handle != NULL)
- /* reallocate array */
- ret = VBHugeAlloc(pArray, pArray -> recsize, ubound, TRUE);
- else
- /* array has never been allocated */
- ret = HA_BADARRAY;
-
- LocalUnlock(hLocalMem);
- return ret;
- }
-